<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of account
 *
 * @author Ron
 */
class Account extends CI_Controller {
    
    public function __construct() {
        parent::__construct();
        $this->load->model('Account_model');
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
    }
    public function index(){
        
        
    }

    public function login(){
        $config = array(
               array(
                     'field'   => 'username', 
                     'label'   => '用户名/E-Mail', 
                     'rules'   => 'required'
                  ),
               array(
                     'field'   => 'password', 
                     'label'   => '密码', 
                     'rules'   => 'required'
                  )
            );
        $this->form_validation->set_rules($config);
        $this->form_validation->set_message('required','你还没填写%s呢：）');
        
        $this->load->view('shared/header');
        if ($this->form_validation->run() == FALSE)
        {
         $this->load->view('account/login');
        }
        else
        {
         $this->load->view('shared/formsuccess');
        }
        $this->load->view('shared/footer');
       
    }
    
    public function register(){
        
        $config = array(
               array(
                     'field'   => 'username', 
                     'label'   => '用户名', 
                     'rules'   => 'required|is_unique[accounts.username]'
                  ),
               array(
                     'field'   => 'password', 
                     'label'   => '密码', 
                     'rules'   => 'required|matches[passconf]'
                  ),
               array(
                     'field'   => 'passconf', 
                     'label'   => '重复密码', 
                     'rules'   => 'required'
                  ),   
               array(
                     'field'   => 'email', 
                     'label'   => 'E-Mail', 
                     'rules'   => 'required|valid_email|is_unique[accounts.email]'
                  )
            );
        $this->form_validation->set_rules($config);
        $this->form_validation->set_message('required','你还没填写%s呢：）');
        $this->form_validation->set_message('valid_email','%s格式不正确');
        $this->form_validation->set_message('matches','两次输入的%s不一致');
         $this->form_validation->set_message('is_unique','该%s已被使用，换一个吧：）');
        
        $this->load->view('shared/header');
        if ($this->form_validation->run() == FALSE)
        {
         $this->load->view('account/register');
        }
        else
        {
         $this->load->view('shared/formsuccess');
        }
        $this->load->view('shared/footer');
    }
    
}
